home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Dots & Pixels / sources / stopwatch.cp < prev    next >
Text File  |  1995-09-29  |  949b  |  59 lines

  1. #include <Timer.h>
  2.  
  3. #include "stopwatch.h"
  4.  
  5. const long stopwatch::starting_value = 0x80000000;    // max # of microseconds
  6.  
  7. stopwatch::stopwatch()
  8. {
  9.     tmAddr     = 0;    // no Task
  10.     tmWakeUp   = 0;    // see IM VI 23-7  'you should set tmWakeUp and tmReserved to zero
  11.     tmReserved = 0;    // when you first install an extended Time Manager task.
  12.     InsXTime( (QElem *)(TMTask *)this);
  13.     running = false;
  14. }
  15.  
  16. stopwatch::~stopwatch()
  17. {
  18.     if( running)
  19.     {
  20.         (void)stop();
  21.     }
  22. };
  23.  
  24. long stopwatch::read()
  25. {
  26.     long result = 0;
  27.     if( running)
  28.     {
  29.         result = stop();
  30.         InsXTime( (QElem *)(TMTask *)this);
  31.         restart( 0);
  32.     }
  33.     return result;
  34. }
  35.  
  36. long stopwatch::stop()
  37. {
  38.     long result = 0;
  39.     if( running)
  40.     {
  41.         RmvTime( (QElem *)(TMTask *)this);
  42.         running = false;
  43.         if( tmCount != 0)
  44.         {
  45.             result = tmCount - starting_value;
  46.         }
  47.     }
  48.     return result;
  49. }
  50.  
  51. void stopwatch::restart( unsigned long to_go)
  52. {
  53.     if( !running)
  54.     {
  55.         PrimeTime( (QElem *)(TMTask *)this, to_go);
  56.         running = true;
  57.     }
  58. }
  59.